/**
 * [EmployeeController description]
 */
EmployeeFilterController = function () {

    // 获取门店列表
    this.getShopList = function(param, prePageParam,isFilter) {
        var serverUrl = App.serverUrl +　"/app/order/shops.do";
        var sucFunc = function (result) {
            console.info("获取门店列表返回:" + JSON.stringify(result));
            if (result && result.success) {
                // 服务器返回成功 
                employeeFilterParam.inited = true;
                var cityListData = result.resultObject.pageData;
                if (cityListData && cityListData.length == 1) {
                    var city = cityListData[0];
                    console.info("获取city返回:" + JSON.stringify(city));
                    var shops = city.shops;
                    if (shops && shops.length == 1) {
                        var shop = shops[0];
                        employeeFilterParam.singleShop=true;
                        employeeFilterParam.cache = cityListData;
                        /*if(isFilter) {
                            employeeFilterParam.params.shopId=shop.shopId;
                            employeeFilterParam.params.shopName=shop.shopName;
                        }*/
                    } else {
                        employeeFilterParam.cache = cityListData;
                        employeeFilterParam.singleShop = false;
                    }
                } else if (!cityListData || cityListData.length == 0) {
                    DialogUtil.dialogWarn("未获取门店");
                    employeeFilterParam.singleShop = false;
                    CommonUtil.render($("#employeeStoreListPage .page-body #selectEmployeeShopDiv"), "employeeStoreTPLEmpty", {mts: pageData.list});
                    return;
                } else {
                    employeeFilterParam.cache = cityListData;
                    employeeFilterParam.singleShop = false;
                }
               // if(isFilter) {
                    
                   // CommonUtil.render($("#employeeFilterPage #employeeShopDiv"), "employeeTpl", {data: employeeFilterParam});
              //  }
                if(prePageParam) {
                    //设置筛选项
                    if(!employeeFilterParam.singleShop) {
                        //设置筛选项
                        //设置门店
                        if (prePageParam.params.shopId != '') {
                            employeeFilterParam.params.shopId=prePageParam.params.shopId;
                            employeeFilterParam.params.shopName=prePageParam.params.shopName;
                            if (!employeeFilterParam.singleShop) {
                                $('#employeeFilterPage .page-body .store-name').html(employeeFilterParam.params.shopName);
                            }
                        } else {
                            //不是单门店的情况
                            employeeFilterParam.params.shopId='';
                            employeeFilterParam.params.shopName='';
                            $('#employeeFilterPage .page-body .store-name').html("全部门店");
                        }
                    } else {
                        $('#employeeFilterPage #filterEmployeeStore').addClass("hide");
                    }

                    //设置在职状态
                    if (prePageParam.params.onjobStatus != '') {
                        employeeFilterParam.params.onjobStatus=prePageParam.params.onjobStatus;
                        $('#employeeFilterPage .filter-item').each(function(){
                            var onjobStatus = $(this).attr("onjobStatus");
                            if (onjobStatus && onjobStatus == prePageParam.params.onjobStatus) {
                                $(this).addClass("selected");
                                return;
                            }
                        });

                    }
                    //设置员工角色
                    if (prePageParam.params.roleId != '') {
                        employeeFilterParam.params.roleId=prePageParam.params.roleId;
                        $('#employeeFilterPage .filter-item').each(function(){
                            var roleId = $(this).attr("roleId");
                            if (roleId && roleId == prePageParam.params.roleId) {
                                $(this).addClass("selected");
                                return;
                            }
                        });
                    }
                }

            } else {
                DialogUtil.dialogWarn(result.msg);
            }
        }
        CommonUtil.sendJsonpRequest({
            url: serverUrl,
            params: param,
            success: sucFunc
        });
    };  
};